<template>
  <view class="goods_item">
    <!-- 左边的照片区域-->
    <view class="goods-item-lift">
      <radio :checked="goods.goods_state" color="#C00000" v-if="isShowRadio" @click="radioClickHandler"></radio>
      <image class="left-item-img" :src="goods.goods_small_logo || defaultImage"></image>
    </view>
    <!-- 右边的文字区域-->
    <view class="goods-item-right">
      <view class="goods-item-name">
        {{goods.goods_name}}
      </view>
      <!-- 价格-->
      <view class="goods-info-box">
        <view class="goods-item-price">￥{{goods.goods_price | tofixed(goods.goods_price)}}</view>
        <uni-number-box :min="1" :value="goods.goods_count" v-if="isShowNum" @change="numberChangeHander"></uni-number-box>
      </view>

    </view>
  </view>
</template>

<script>
  export default {
    props: {
      goods: {
        type: Object,
        default: {},
      },
      isShowRadio: {
        type: Boolean,
        default: false,
      },
      isShowNum: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        defaultImage: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
      };
    },
    methods: {
      radioClickHandler() {
        this.$emit('radio-change', {
          goods_id: this.goods.goods_id,
          goods_state: !this.goods.goods_state,
        })
      },
      numberChangeHander(val) {
        console.log(val);
        this.$emit('num-change', {
          goods_id: this.goods.goods_id,
          goods_count: +val,
        })
      }
    },
    filters: {
      tofixed(num) {
        return Number(num).toFixed(2)
      }
    }
  }
</script>

<style lang="scss">
  .goods_item {
    display: flex;
    margin: 10px 5px;
    border-bottom: 1px solid #efefef;
    // 让 goods-item 项占满整个屏幕的宽度
    width: 750rpx;
    // 设置盒模型为 border-box
    box-sizing: border-box;

    .goods-item-lift {
      margin-right: 5px;
      display: flex;
      justify-content: center;
      align-items: center;

      .left-item-img {
        height: 100px;
        width: 100px;
        display: block;
      }
    }

    .goods-item-right {
      display: flex;
      flex: 1;
      flex-direction: column;
      justify-content: space-between;

      .goods-item-name {
        font-size: 13px;
      }

      .goods-info-box {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .goods-item-price {
          font-size: 20px;
          color: #C00000;
        }
      }

    }
  }
</style>
